<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="show"
      width="60%"
      :before-close="handleClose"
    >
      <span>姓名:</span>
      <el-select
        v-model="queryForm.name"
        placeholder="请选择"
        style="width: 200px; margin: 0 0 0 0.5vw"
        size="small"
        clearable
      >
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <el-button
        type="primary"
        size="small"
        @click="adminExport"
        style="margin: 0 0 0 1vw"
        >导出</el-button
      >
      <!-- 气泡确认框 -->
      <el-popover
        placement="right"
        width="160"
        v-model="visible"
        style="margin: 0 0 0 1vw"
      >
        <p>确定要一键审核吗?</p>
        <div style="text-align: right; margin: 0">
          <el-button size="mini" type="text" @click="visible = false"
            >取消</el-button
          >
          <el-button type="primary" size="mini" @click="visible = false"
            >确定</el-button
          >
        </div>
        <el-button
          type="danger"
          size="small"
          style="margin: 0 0 0 1vw"
          slot="reference"
          >一键审核</el-button
        >
      </el-popover>
      <el-table :data="datas" style="width: 100%; margin: 1vw 0 0" border>
        <el-table-column prop="projectCode" label="项目编号"> </el-table-column>
        <el-table-column prop="id" label="日报编号"> </el-table-column>
        <el-table-column
          prop="content"
          label="日报内容"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column prop="date" label="填报时间"> </el-table-column>
        <el-table-column prop="name" label="填报人"> </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == '0'" type="info">未审核</el-tag>
            <el-tag v-if="scope.row.status == '1'" type="success"
              >已审核</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="control" label="操作栏">
          <template slot-scope="scope">
            <el-button
              type="warning"
              size="small"
              @click="deterDaily(scope.row)"
              v-if="scope.row.status == '0'"
              >审核日报</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
export default {
  props: ["show", "title", "code"],
  data() {
    return {
      queryForm: {
        name: "",
      },
      options: [],
      datas: [],
      visible: false,
    };
  },
  watch: {
    show(newV) {
      if (newV == true) {
        //获取列表
        let obj = {
          projectCode: this.code,
        };
        this.getUser(obj);
        this.getlist({ pageNo: 1, pageSize: 5, projectCode: this.code });
      }
    },
    "queryForm.name"(newV) {
      if (newV) {
        let obj = {
          name: "",
        };
        obj.name = this.options.find((res) => {
          return res.value == newV;
        }).label;
        obj = Object.assign(obj, {
          pageNo: 1,
          pageSize: 5,
          projectCode: this.code,
        });
        this.getlist(obj);
      }
    },
  },
  methods: {
    getlist(e) {
      this.$http.get("/adminGetDaily", { params: e }).then((res) => {
        if (res.code == 200) {
          this.datas = res.data.data;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    handleClose() {
      this.$emit("checkClose", true);
      this.queryForm.name = "";
    },
    adminExport() {
      let obj = {
        projectCode: this.code,
        name: "",
      };
      if (this.queryForm.name != "") {
        obj.name = this.options.find((res) => {
          return res.value == this.queryForm.name;
        }).label;
      }
      this.$http.post("/exportExcel", obj).then((res) => {
        console.log(res, "res");
        //处理跨域问题
        axios.get(res.data.url, { responseType: "blob" }).then((resk) => {
          let downURL = window.URL.createObjectURL(resk.data);
          let a = document.createElement("a");
          a.href = downURL;
          a.download = "日报";
          document.body.append(a);
          a.style.display = "none";
          a.click();
        });
      });
    },
    getUser(e) {
      this.$http.get("/getExportUser", { params: e }).then((res) => {
        if (res.code == 200) {
          this.options = res.data;
        }
      });
    },
    search() {},
    /* 审核日报 */
    deterDaily(e) {
      /* 有id是单条审核 */
      if (e.id) {
        let obj = {
          projectCode: e.projectCode,
          id: e.id,
        };
        this.$http.post("/examineDaliy", obj).then((res) => {
          if (res.code == 200) {
            this.$message.success("审核成功");
            this.getlist({ pageNo: 1, pageSize: 5, projectCode: this.code });
          } else {
            this.$message.error(res.msg);
          }
        });
      }
    },
  },
};
</script>

<style scoped>
</style>